package com.example.programexpert

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge

class MainActivity : ComponentActivity() {
    val expert = ProgramExpert()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.layout_my)

        // 实现语言推荐功能
        val spinner = findViewById<Spinner>(R.id.spinner)
        val button = findViewById<Button>(R.id.button)
        val textView = findViewById<TextView>(R.id.textView)
        button.setOnClickListener {
            textView.text = expert.getLanguage(feature=spinner.selectedItem.toString())
        }

        // 实现动态添加文本功能
        val dynamicTexts: LinearLayout = findViewById(R.id.dynamic_texts)
        val buttonAddText: Button = findViewById(R.id.button2)
        buttonAddText.setOnClickListener{
            val count = dynamicTexts.childCount + 1
            val dynamicText = TextView(this).apply {
                text = "This is a new TextView: $count\n"
                textSize = 16f
                setPadding(16, 12, 16, 12)
            }
            dynamicTexts.addView(dynamicText)
        }
    }
}